package com.shangdiao.sd_server.c_client.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shangdiao.sd_server.constant.Constant;
import com.shangdiao.sd_server.constant.ErrorCode;
import com.shangdiao.sd_server.generator.pojo.SdCompany;
import com.shangdiao.sd_server.generator.pojo.SdCompanyPhoto;
import com.shangdiao.sd_server.generator.pojo.SdCompanyPhotoExample;
import com.shangdiao.sd_server.generator.pojo.SdInternship;
import com.shangdiao.sd_server.generator.pojo.SdInternshipExample;
import com.shangdiao.sd_server.generator.pojo.SdInternshipReview;
import com.shangdiao.sd_server.generator.pojo.SdInternshipReviewExample;
import com.shangdiao.sd_server.generator.pojo.SdParttime;
import com.shangdiao.sd_server.generator.pojo.SdParttimeExample;
import com.shangdiao.sd_server.generator.pojo.SdParttimeReview;
import com.shangdiao.sd_server.generator.pojo.SdParttimeReviewExample;
import com.shangdiao.sd_server.generator.pojo.SdPersonBase;
import com.shangdiao.sd_server.pojo.ResponseMsg;
import com.shangdiao.sd_server.pojo.Row;
import com.shangdiao.sd_server.service.CompanyService;
import com.shangdiao.sd_server.service.DicService;
import com.shangdiao.sd_server.service.PersonService;
import com.shangdiao.sd_server.service.PostService;
import com.shangdiao.sd_server.service.RedisService;
import com.shangdiao.sd_server.util.DateUtil;
import com.shangdiao.sd_server.util.RequestUtil;
import com.shangdiao.sd_server.util.StringUtil;

/**
 * 企业公开信息
 * @author mary
 *
 */
@Controller
@RequestMapping("/open/company")
public class CompanyInfoController {
	
	@Autowired
	DicService dicService;
	@Autowired
	CompanyService companyService;
	@Autowired
	RedisService redisService;
	@Autowired
	PostService postService;
	@Autowired
	PersonService personService;
	
	@RequestMapping(value = { "/getInfo.json" })
	@ResponseBody
	public ResponseMsg getInfo(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			if(companyId == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			Row result = new Row();
			SdCompany company = companyService.selectCompanyById(companyId);
			result.put("identityFlag", "c");//身份标识
			result.put("companyName", company.getCompanyName());//公司名称
			result.put("fieldId", company.getDicFieldId());//eee
			result.put("fieldName", company.getDicFieldName());//
			String logo = company.getLogo();
			if(StringUtil.isBlank(logo)){
				result.put("logo", "");
			}else{
				result.put("logo", Constant.DOMAIN + company.getLogo());//
			}
			result.put("website", company.getWebsite());//
			result.put("districtId", company.getDistrictId());//
			result.put("district", company.getDistrict());//
			result.put("location", company.getLocation());//
			result.put("email", company.getEmail());//
			result.put("tel", company.getTel());//
			result.put("intro", company.getIntro());//
			SdCompanyPhotoExample example = new SdCompanyPhotoExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdCompanyPhoto> companyPhotoList = companyService.selectCompanyPhoto(example);
			List<String> photoList = new ArrayList<String>();
			for(SdCompanyPhoto companyPhoto : companyPhotoList){
				photoList.add(Constant.DOMAIN + companyPhoto.getCompanyPhotoUrl());
			}
			result.put("photoList", photoList);//
			return new ResponseMsg("查询成功", ErrorCode.OK, result);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("更新失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	
	@RequestMapping(value = { "/selectMyPost.json" })
	@ResponseBody
	public ResponseMsg selectMyPost(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer companyId = RequestUtil.getInt(request, "companyId");
			if(companyId == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			//实习岗位
			SdInternshipExample example1 = new SdInternshipExample();
			example1.or().andCompanyIdEqualTo(companyId)
				.andStatusEqualTo(Constant.STATUS_ON)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdInternship> internshipList = postService.selectInternshipList(example1);
			SdCompany company = companyService.selectCompanyById(companyId);
			List<Row> resultList1 = new ArrayList<Row>();
			for(SdInternship internship : internshipList){
				Row result = new Row();
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("companyName", company.getCompanyName());
				result.put("internshipId", internship.getInternshipId());
				result.put("internshipName", internship.getInternshipName());
				result.put("dicInternshipFieldName", internship.getDicInternshipFieldName());
				result.put("district", internship.getDistrict() == null ? "" : internship.getDistrict());
				result.put("location", internship.getLocation() == null ? "" : internship.getLocation());
				result.put("salary", internship.getMinSalary() + "K ~ " + internship.getMaxSalary() + "K");
				result.put("createDate", DateUtil.DateToString(internship.getCreateDate(), DateUtil.FORMAT_TWO));
				resultList1.add(result);
			}
			//兼职岗位
			SdParttimeExample example2 = new SdParttimeExample();
			example2.or().andCompanyIdEqualTo(companyId)
				.andStatusEqualTo(Constant.STATUS_ON)
				.andDelEqualTo(Constant.DEL_NO)
				.andDeadlineGreaterThanOrEqualTo(new Date());
			List<SdParttime> parttimeList = postService.selectParttimeList(example2);
			List<Row> resultList2 = new ArrayList<Row>();
			for(SdParttime parttime : parttimeList){
				Row result = new Row();
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("parttimeId", parttime.getParttimeId());
				result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
				result.put("district", parttime.getDistrict());
				result.put("salary", parttime.getSalary());
				result.put("unit", StringUtil.isBlank(parttime.getUnit()) ? "" : parttime.getUnit());
				result.put("hasAllowance", parttime.getHasAllowance());
				result.put("dicSettlementName", parttime.getDicSettlementName());
				result.put("district", parttime.getDistrict() == null ? "" : parttime.getDistrict());
				result.put("location", parttime.getLocation() == null ? "" : parttime.getLocation());
				result.put("startDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.LONG_DATE_FORMAT));
				result.put("endDate", DateUtil.DateToString(parttime.getEndData(), DateUtil.LONG_DATE_FORMAT));
				result.put("workDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.SHORT_DATE_FORMAT) + "至" + DateUtil.DateToString(parttime.getEndData(), DateUtil.SHORT_DATE_FORMAT));
				resultList2.add(result);
			}
			Row result = new Row();
			result.put("internshipList", resultList1);
			result.put("parttimeList", resultList2);
			return new ResponseMsg("查询成功", ErrorCode.OK, result);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	
	@RequestMapping(value = { "/selectInternshipDetail.json" })
	@ResponseBody
	public ResponseMsg selectInternshipDetail(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer internshipId = RequestUtil.getInt(request, "internshipId");
			if(internshipId == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			SdInternship internship = postService.selectInternship(internshipId);
			if(internship == null){
				return new ResponseMsg("此岗位已删除", ErrorCode.ERROR, null);
			}
			Integer companyId = internship.getCompanyId();
			SdCompany company = companyService.selectCompanyById(companyId);
			Row result = new Row();
			result.put("companyId", companyId);//公司ID
			result.put("companyName", company.getCompanyName());//公司名称
			result.put("dicFieldId", company.getDicFieldId());//
			result.put("dicFieldName", company.getDicFieldName());//
			result.put("companyTel", company.getTel());//
			String logo = company.getLogo();
			if(StringUtil.isBlank(logo)){
				result.put("logo", "");
			}else{
				result.put("logo", Constant.DOMAIN + company.getLogo());//
			}
			SdCompanyPhotoExample example = new SdCompanyPhotoExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdCompanyPhoto> companyPhotoList = companyService.selectCompanyPhoto(example);
			List<String> photoList = new ArrayList<String>();
			for(SdCompanyPhoto companyPhoto : companyPhotoList){
				photoList.add(Constant.DOMAIN + companyPhoto.getCompanyPhotoUrl());
			}
			result.put("photoList", photoList);//企业照片墙
			result.put("internshipId", internship.getInternshipId());
			result.put("internshipName", internship.getInternshipName());
			result.put("dicInternshipFieldId", internship.getDicInternshipFieldId());
			result.put("dicInternshipFieldName", internship.getDicInternshipFieldName());
			result.put("salary", internship.getMinSalary() + "K ~ " + internship.getMaxSalary() + "K");
			result.put("minSalary", internship.getMinSalary());
			result.put("maxSalary", internship.getMaxSalary());
			result.put("recruitingNumbers", internship.getRecruitingNumbers());
			result.put("minEducationName", internship.getMinEducationName());
			result.put("districtId", internship.getDistrictId());
			result.put("district", internship.getDistrict());
			result.put("location", internship.getLocation());
			result.put("desc", internship.getDescription());
			result.put("requirement", internship.getRequirement());
			result.put("tel", internship.getTel());
			result.put("createDate", DateUtil.DateToString(internship.getCreateDate(), DateUtil.LONG_DATE_FORMAT));
			//评论
			SdInternshipReviewExample reviewExample = new SdInternshipReviewExample();
			reviewExample.or().andInternshipIdEqualTo(internshipId)
				.andDelEqualTo(Constant.DEL_NO);
			reviewExample.setOrderByClause("create_time desc limit 0,2");
			List<SdInternshipReview> reviewList = postService.selectInternshipReview(reviewExample);
			List<Row> resultList = new ArrayList<Row>();
			for(SdInternshipReview review : reviewList){
				Row reviewRow = new Row();
				Integer anonymityFlag = review.getAnonymityFlag();
				if(anonymityFlag == Constant.COLLECT_OFF){//不匿名
					Integer personId = review.getPersionId();
					SdPersonBase personBase = personService.selectPersonBaseById(personId);
					String personLogo = personBase.getLogo();
					if(StringUtil.isBlank(personLogo)){
						reviewRow.put("logo", "");
					}else{
						reviewRow.put("logo", Constant.DOMAIN + personLogo);
					}
					reviewRow.put("personName", personBase.getPersonName());
				}else{
					reviewRow.put("personName", Constant.ANONYMITY_NAME);
					reviewRow.put("logo", "");
				}
				reviewRow.put("anonymityFlag", anonymityFlag);
				reviewRow.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
				reviewRow.put("review", review.getReview());
				resultList.add(reviewRow);
			}
			result.put("reviewList", resultList);
			return new ResponseMsg("查询成功", ErrorCode.OK, result);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectParttimeDetail.json" })
	@ResponseBody
	public ResponseMsg selectParttimeDetail(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer parttimeId = RequestUtil.getInt(request, "parttimeId");
			if(parttimeId == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			SdParttime parttime = postService.selectParttime(parttimeId);
			if(parttime == null){
				return new ResponseMsg("此岗位已删除", ErrorCode.ERROR, null);
			}
			Integer companyId = parttime.getCompanyId();
			SdCompany company = companyService.selectCompanyById(companyId);
			Row result = new Row();
			result.put("companyId", companyId);//公司ID
			result.put("companyName", company.getCompanyName());//公司名称
			result.put("dicFieldId", company.getDicFieldId());//
			result.put("dicFieldName", company.getDicFieldName());//
			result.put("companyTel", company.getTel());//
			String logo = company.getLogo();
			if(StringUtil.isBlank(logo)){
				result.put("logo", "");
			}else{
				result.put("logo", Constant.DOMAIN + company.getLogo());//
			}
			SdCompanyPhotoExample example = new SdCompanyPhotoExample();
			example.or().andCompanyIdEqualTo(companyId)
				.andDelEqualTo(Constant.DEL_NO);
			List<SdCompanyPhoto> companyPhotoList = companyService.selectCompanyPhoto(example);
			List<String> photoList = new ArrayList<String>();
			for(SdCompanyPhoto companyPhoto : companyPhotoList){
				photoList.add(Constant.DOMAIN + companyPhoto.getCompanyPhotoUrl());
			}
			result.put("photoList", photoList);//企业照片墙
			result.put("parttimeId", parttimeId);
			result.put("dicParttimeFieldId", parttime.getDicParttimeFieldId());
			result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
			String dicSettlementName = parttime.getDicSettlementName();
			result.put("salary", parttime.getSalary());
			result.put("unit", StringUtil.isBlank(parttime.getUnit()) ? "" : parttime.getUnit());
			result.put("salary1", parttime.getSalary());
			result.put("dicSettlementId", parttime.getDicSettlementId());
			result.put("dicSettlementName", dicSettlementName);
			result.put("hasAllowance", parttime.getHasAllowance());
			result.put("workDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.SHORT_DATE_FORMAT) + "至" + DateUtil.DateToString(parttime.getEndData(), DateUtil.SHORT_DATE_FORMAT)); 
			result.put("workTime", DateUtil.DateToString(parttime.getStartTime(), DateUtil.LONG_TIME_MINUTE_FORMAT) + "-" + DateUtil.DateToString(parttime.getEndTime(), DateUtil.LONG_TIME_MINUTE_FORMAT)); 
			result.put("startData", DateUtil.DateToString(parttime.getStartData(), DateUtil.LONG_DATE_FORMAT));
			result.put("endData", DateUtil.DateToString(parttime.getEndData(), DateUtil.LONG_DATE_FORMAT));
			result.put("startTime", DateUtil.DateToString(parttime.getStartTime(), DateUtil.LONG_TIME_MINUTE_FORMAT));
			result.put("endTime", DateUtil.DateToString(parttime.getEndTime(), DateUtil.LONG_TIME_MINUTE_FORMAT));
			result.put("recruitingNumbers", parttime.getRecruitingNumbers());
			result.put("districtId", parttime.getDistrictId());
			result.put("district", parttime.getDistrict());
			result.put("location", parttime.getLocation());
			result.put("desc", parttime.getDescription());
			result.put("requirement", parttime.getRequirement());
			result.put("deadline", DateUtil.DateToString(parttime.getDeadline(), DateUtil.LONG_DATE_FORMAT));
			result.put("tel", parttime.getTel());
			//评论
			SdParttimeReviewExample reviewExample = new SdParttimeReviewExample();
			reviewExample.or().andParttimeIdEqualTo(parttimeId)
				.andDelEqualTo(Constant.DEL_NO);
			reviewExample.setOrderByClause("create_time desc limit 0,2");
			List<SdParttimeReview> reviewList = postService.selectParttimeReview(reviewExample);
			List<Row> resultList = new ArrayList<Row>();
			for(SdParttimeReview review : reviewList){
				Row reviewRow = new Row();
				Integer anonymityFlag = review.getAnonymityFlag();
				if(anonymityFlag == Constant.COLLECT_OFF){//不匿名
					Integer personId = review.getPersionId();
					SdPersonBase personBase = personService.selectPersonBaseById(personId);
					String personLogo = personBase.getLogo();
					if(StringUtil.isBlank(personLogo)){
						reviewRow.put("logo", "");
					}else{
						reviewRow.put("logo", Constant.DOMAIN + personLogo);
					}
					reviewRow.put("personName", personBase.getPersonName());
				}else{
					reviewRow.put("personName", Constant.ANONYMITY_NAME);
					reviewRow.put("logo", "");
				}
				reviewRow.put("anonymityFlag", anonymityFlag);
				reviewRow.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
				reviewRow.put("review", review.getReview());
				resultList.add(reviewRow);
			}
			result.put("reviewList", resultList);
			return new ResponseMsg("查询成功", ErrorCode.OK, result);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/selectAllReview.json" })
	@ResponseBody
	public ResponseMsg selectAllReview(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer postId = RequestUtil.getInt(request, "postId");
			Integer postFlag = RequestUtil.getInt(request, "postFlag");
			int curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			int pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			List<Row> resultList = new ArrayList<Row>();
			int start = (curPage - 1) * pageSize;
			if(postId == 0 || postFlag == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			if(postFlag == Constant.POST_FLAG_PARTTIME){
				SdParttimeReviewExample reviewExample = new SdParttimeReviewExample();
				reviewExample.or().andParttimeIdEqualTo(postId)
					.andDelEqualTo(Constant.DEL_NO);
				reviewExample.setOrderByClause("create_time desc limit " + start + "," + pageSize);
				List<SdParttimeReview> reviewList = postService.selectParttimeReview(reviewExample);
				for(SdParttimeReview review : reviewList){
					Row reviewRow = new Row();
					Integer anonymityFlag = review.getAnonymityFlag();
					if(anonymityFlag == Constant.COLLECT_OFF){//不匿名
						Integer personId = review.getPersionId();
						SdPersonBase personBase = personService.selectPersonBaseById(personId);
						String personLogo = personBase.getLogo();
						if(StringUtil.isBlank(personLogo)){
							reviewRow.put("logo", "");
						}else{
							reviewRow.put("logo", Constant.DOMAIN + personLogo);
						}
						reviewRow.put("personName", personBase.getPersonName());
					}else{
						reviewRow.put("personName", Constant.ANONYMITY_NAME);
						reviewRow.put("logo", "");
					}
					reviewRow.put("anonymityFlag", anonymityFlag);
					reviewRow.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
					reviewRow.put("review", review.getReview());
					resultList.add(reviewRow);
				}

			}else if(postFlag == Constant.POST_FLAG_INTERNSHIP){
				SdInternshipReviewExample reviewExample = new SdInternshipReviewExample();
				reviewExample.or().andInternshipIdEqualTo(postId)
					.andDelEqualTo(Constant.DEL_NO);
				reviewExample.setOrderByClause("create_time desc limit " + start + "," + pageSize);
				List<SdInternshipReview> reviewList = postService.selectInternshipReview(reviewExample);
				for(SdInternshipReview review : reviewList){
					Row reviewRow = new Row();
					Integer anonymityFlag = review.getAnonymityFlag();
					if(anonymityFlag == Constant.COLLECT_OFF){//不匿名
						Integer personId = review.getPersionId();
						SdPersonBase personBase = personService.selectPersonBaseById(personId);
						String personLogo = personBase.getLogo();
						if(StringUtil.isBlank(personLogo)){
							reviewRow.put("logo", "");
						}else{
							reviewRow.put("logo", Constant.DOMAIN + personLogo);
						}
						reviewRow.put("personName", personBase.getPersonName());
					}else{
						reviewRow.put("personName", Constant.ANONYMITY_NAME);
						reviewRow.put("logo", "");
					}
					reviewRow.put("anonymityFlag", anonymityFlag);
					reviewRow.put("createTime", DateUtil.DateToString(review.getCreateTime(), DateUtil.FORMAT_ONE));
					reviewRow.put("review", review.getReview());
					resultList.add(reviewRow);
				}
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 热门职位 现在搜索的是最近发布的岗位按发布时间倒序
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/selectHotInternship.json" })
	@ResponseBody
	public ResponseMsg selectHotInternship(HttpServletRequest request, HttpServletResponse response) {
		try{
			int curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			int pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			List<Row> resultList = new ArrayList<Row>();
			int start = (curPage - 1) * pageSize;
			SdInternshipExample example = new SdInternshipExample();
			example.or().andDelEqualTo(Constant.DEL_NO);
			example.setOrderByClause("create_date desc limit " + start + "," + pageSize);
			List<SdInternship> internshipList = postService.selectInternshipList(example);
			for(SdInternship internship : internshipList){
				Row result = new Row();
				Integer companyId = internship.getCompanyId();
				SdCompany company = companyService.selectCompanyById(companyId);
				if(company == null || company.getDel() == Constant.DEL_YES){
					continue;
				}
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("companyName", company.getCompanyName());
				result.put("internshipId", internship.getInternshipId());
				result.put("internshipName", internship.getInternshipName());
				result.put("districtId", internship.getDistrictId());
				result.put("district", internship.getDistrict());
				result.put("location", internship.getLocation());
				result.put("salary", internship.getMinSalary() + "K ~ " + internship.getMaxSalary() + "K");
				result.put("createDate", DateUtil.DateToString(internship.getCreateDate(), DateUtil.FORMAT_TWO));
				result.put("postFlag", Constant.POST_FLAG_INTERNSHIP);
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 热门职位 现在搜索的是最近发布的岗位按发布时间倒序
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/selectHotParttime.json" })
	@ResponseBody
	public ResponseMsg selectHotParttime(HttpServletRequest request, HttpServletResponse response) {
		try{
			int curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			int pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			List<Row> resultList = new ArrayList<Row>();
			int start = (curPage - 1) * pageSize;
			SdParttimeExample example = new SdParttimeExample();
			example.or().andDelEqualTo(Constant.DEL_NO)
				.andDeadlineGreaterThanOrEqualTo(new Date());
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdParttime> parttimeList = postService.selectParttimeList(example);
			for(SdParttime parttime : parttimeList){
				Row result = new Row();
				Integer companyId = parttime.getCompanyId();
				SdCompany company = companyService.selectCompanyById(companyId);
				if(company == null || company.getDel() ==  Constant.DEL_YES){
					continue;
				}
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("parttimeId", parttime.getParttimeId());
				result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
				result.put("districtId", parttime.getDistrictId());
				result.put("district", parttime.getDistrict());
				result.put("location", parttime.getLocation());
				String dicSettlementName = parttime.getDicSettlementName();
				result.put("salary", parttime.getSalary());
				result.put("unit", StringUtil.isBlank(parttime.getUnit()) ? "" : parttime.getUnit());
				result.put("hasAllowance", parttime.getHasAllowance());
				result.put("dicSettlementName", dicSettlementName);
				result.put("startDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.LONG_DATE_FORMAT));
				result.put("endDate", DateUtil.DateToString(parttime.getEndData(), DateUtil.LONG_DATE_FORMAT));
				result.put("workDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.SHORT_DATE_FORMAT) + "至" + DateUtil.DateToString(parttime.getEndData(), DateUtil.SHORT_DATE_FORMAT));
				result.put("postFlag", Constant.POST_FLAG_PARTTIME);
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/searchInternship.json" })
	@ResponseBody
	public ResponseMsg searchInternship(HttpServletRequest request, HttpServletResponse response) {
		try{
			int curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			int pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			Integer dicInternshipFieldId = RequestUtil.getInt(request, "dicInternshipFieldId", 0);
			String condition = RequestUtil.get(request, "condition", "");
			//实习岗位
			SdInternshipExample example = new SdInternshipExample();
			if(dicInternshipFieldId != 0){
				example.or().andStatusEqualTo(Constant.STATUS_ON)
					.andDelEqualTo(Constant.DEL_NO)
					.andDicInternshipFieldIdEqualTo(dicInternshipFieldId)
					.andInternshipNameLike("%" + condition + "%");
			}else{
				example.or().andStatusEqualTo(Constant.STATUS_ON)
					.andInternshipNameLike("%" + condition + "%")
					.andDelEqualTo(Constant.DEL_NO);
			}
			Integer start = (curPage - 1) * pageSize;
			example.setOrderByClause("create_date desc limit " + start + "," + pageSize);
			List<SdInternship> internshipList = postService.selectInternshipList(example);
			List<Row> resultList = new ArrayList<Row>();
			for(SdInternship internship : internshipList){
				Integer companyId = internship.getCompanyId();
				SdCompany company = companyService.selectCompanyById(companyId);
				if(company == null || company.getDel() == Constant.DEL_YES){
					continue;
				}
				Row result = new Row();
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("companyId", company.getCompanyId());
				result.put("companyName", company.getCompanyName());
				result.put("internshipId", internship.getInternshipId());
				result.put("internshipName", internship.getInternshipName());
				result.put("districtId", internship.getDistrictId());
				result.put("district", internship.getDistrict());
				result.put("location", internship.getLocation());
				result.put("salary", internship.getMinSalary() + "K ~ " + internship.getMaxSalary() + "K");
				result.put("createDate", DateUtil.DateToString(internship.getCreateDate(), DateUtil.FORMAT_TWO));
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/searchParttime.json" })
	@ResponseBody
	public ResponseMsg searchParttime(HttpServletRequest request, HttpServletResponse response) {
		try{
			int curPage = RequestUtil.getInt(request, "curPage", Constant.DEFAULT_CUR_PAGE);
			int pageSize = RequestUtil.getInt(request, "pageSize", Constant.DEFAULT_PAGE_SIZE);
			Integer dicParttimeFieldId = RequestUtil.getInt(request, "dicParttimeFieldId", 0);
			String condition = RequestUtil.get(request, "condition", "");
			//兼职岗位
			SdParttimeExample example = new SdParttimeExample();
			if(dicParttimeFieldId != 0){
				example.or().andStatusEqualTo(Constant.STATUS_ON)
					.andDelEqualTo(Constant.DEL_NO)
					.andDeadlineGreaterThanOrEqualTo(new Date())
					.andDicParttimeFieldNameLike("%" + condition + "%")
					.andDicParttimeFieldIdEqualTo(dicParttimeFieldId);
			}else{
				example.or().andStatusEqualTo(Constant.STATUS_ON)
					.andDicParttimeFieldNameLike("%" + condition + "%")
					.andDeadlineGreaterThanOrEqualTo(new Date())
					.andDelEqualTo(Constant.DEL_NO);
			}
			Integer start = (curPage - 1) * pageSize;
			example.setOrderByClause("create_time desc limit " + start + "," + pageSize);
			List<SdParttime> parttimeList = postService.selectParttimeList(example);
			List<Row> resultList = new ArrayList<Row>();
			for(SdParttime parttime : parttimeList){
				Integer companyId = parttime.getCompanyId();
				SdCompany company = companyService.selectCompanyById(companyId);
				if(company == null || company.getDel() == Constant.DEL_YES){
					continue;
				}
				Row result = new Row();
				String logo = company.getLogo();
				if(StringUtil.isBlank(logo)){
					result.put("logo", "");
				}else{
					result.put("logo", Constant.DOMAIN + company.getLogo());//
				}
				result.put("parttimeId", parttime.getParttimeId());
				result.put("dicParttimeFieldName", parttime.getDicParttimeFieldName());
				result.put("districtId", parttime.getDistrictId());
				result.put("district", parttime.getDistrict());
				result.put("location", parttime.getLocation());
				String dicSettlementName = parttime.getDicSettlementName();
				result.put("salary", parttime.getSalary());
				result.put("unit", StringUtil.isBlank(parttime.getUnit()) ? "" : parttime.getUnit());
				result.put("hasAllowance", parttime.getHasAllowance());
				result.put("dicSettlementName", dicSettlementName);
				result.put("startDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.LONG_DATE_FORMAT));
				result.put("endDate", DateUtil.DateToString(parttime.getEndData(), DateUtil.LONG_DATE_FORMAT));
				result.put("workDate", DateUtil.DateToString(parttime.getStartData(), DateUtil.SHORT_DATE_FORMAT) + "至" + DateUtil.DateToString(parttime.getEndData(), DateUtil.SHORT_DATE_FORMAT));
				resultList.add(result);
			}
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("查询失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	public static void main(String[] args) {
		
	}
	
}
